package org.boyan.modules.controller;

import org.boyan.common.api.vo.Result;
import org.boyan.common.util.UUIDGenerator;
import org.boyan.entity.trans.Trans;
import org.boyan.modules.service.TransService;
import org.boyan.modules.vo.TransVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/trans")
public class TransController {
    @Autowired
    private TransService transService;

    @PostMapping("/importTrans")
    public Result addTrans(@RequestBody List<Trans> transList) {
        //给前端传入的transList中遍历增加自动生成的UUID作为trans的Id
        for (Trans t : transList) {
            t.setId(UUIDGenerator.generate());
            t.setTransStatus(1);
        }
        //此处不能创建交易，应该与新增case同步生成
        return Result.OK(transList);
    }

    @GetMapping("/showTransByCaseId/{caseId}")
    public Result showTransByCaseId(@PathVariable("caseId")String id){
        List<TransVO> transVOS=transService.getTransVOListByCaseId(id);
        return Result.OK(transVOS);
    }
}
